<?php

/**
 * Created by PhpStorm.
 * User: Lenovo
 * Date: 2019/5/10
 * Time: 20:34
 */
class T1Action extends Action{
    function f(){
        if ($this->isGet()) {
            $this->display();
            return; }
    }

    function shuaxin(){
        if ($this->isGet()) {
            $files = scandir('Ul');
            unset($files[1]);
            unset($files[0]);
            sort($files);
            $this->ajaxReturn($files);
            return; }
    }

    function delete(){
        if ($this->isPost()) {
            $imgs=$_REQUEST['img'];
            $img=".".$imgs;
            if(empty($img)){
                $this->ajaxReturn(array('status'=>false,'message'=>'未提交数据'));
            }

            if(!is_file($img)){
                $this->ajaxReturn(array('status'=>false,'message'=>$img));
            }
            if(unlink($img)){
                $this->ajaxReturn(array('status'=>true));
            }

            $this->ajaxReturn(array('status'=>false,'message'=>'未能删除'));
        }
    }

    function up(){
        $img = $_FILES["img"];
        if(empty($img)){
            $this->ajaxReturn(array('status'=>false,'message'=>'未选择文件'));
        }
        if(0!=$img['error']){
            $this->ajaxReturn(array('status'=>false,'message'=>'上传失败,错误码：'.$img['error']));
        }

        $pathInfo = pathinfo($img['name']);
        $imgName=time().'.'.$pathInfo['extension'];
        if(move_uploaded_file($img['tmp_name'],"./Ul/$imgName")){
            $this->ajaxReturn(array('status'=>true,'img'=>$imgName));
        }
        $this->ajaxReturn(array('status'=>false,'message'=>'未能写入文件'));
    }
}